﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace POS.ModForm.Bill
{
    public partial class AddItemAdjustPrice : DevExpress.XtraEditors.XtraUserControl
    {
        public AddItemAdjustPrice()
        {
            InitializeComponent();
        }
        public LookUpEdit LookUpProduct
        {
            get { return this.lookUpEditItem; }
        }
        public TextEdit SalePriceControl
        {
            get { return this._SalePrice; }
        }
        public TextEdit SalePriceLowestControl
        {
            get { return this._SalePriceLowest; }
        }
        public SimpleButton AddDetail
        {
            get { return this.btnAdd; }
        }
        public SimpleButton DelDetail
        {
            get { return this.btnDelete; }
        }
        public string ProductID
        {
            get
            {
                if (string.IsNullOrEmpty(this.lookUpEditItem.Text.Trim()) || this.lookUpEditItem.Text.Trim() == "输入货品简码")
                {
                    this.lookUpEditItem.Select();
                    throw new Exception("请选择要销售的货品！");
                }
                DataRowView item = (DataRowView)this.lookUpEditItem.GetSelectedDataRow();
                return item.Row["ProductID"].ToString();
            }
        }
        public decimal SalePrice
        {
            get
            {
                if (string.IsNullOrEmpty(this._SalePrice.Text.Trim()) || Convert.ToDecimal(this._SalePrice.Text.Trim()) <= 0)
                {
                    this._SalePrice.Select();
                    throw new Exception("请输入货品的最新销售单价！");
                }
                return Convert.ToDecimal(this._SalePrice.Text.Trim());
            }
        }
        public decimal SalePriceLowest
        {
            get
            {
                if (string.IsNullOrEmpty(this._SalePriceLowest.Text.Trim()) || Convert.ToDecimal(this._SalePriceLowest.Text.Trim()) <= 0)
                {
                    this._SalePriceLowest.Select();
                    throw new Exception("请输入货品的最新最低销售单价！");
                }
                return Convert.ToDecimal(this._SalePriceLowest.Text.Trim());
            }
        }
        private void AddItemAdjustPrice_Load(object sender, EventArgs e)
        {
            this.lookUpEditItem.Properties.ShowHeader = true;
            this.lookUpEditItem.Properties.PopupWidth = 600;
            this.lookUpEditItem.Properties.PopupWidth = 300;
        }
        private void _SalePrice_Click(object sender, EventArgs e)
        {
            this._SalePrice.SelectAll();
        }
        private void _SalePriceLowest_Click(object sender, EventArgs e)
        {
            this._SalePriceLowest.SelectAll();
        }
        private void lookUpEditItem_Leave(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.lookUpEditItem.Text.Trim()) || this.lookUpEditItem.Text.Trim()=="输入货品简码")
            {
                return;
            }
            this._SalePrice.SelectAll();
            DataRowView item = (DataRowView)this.lookUpEditItem.GetSelectedDataRow();
            this._SalePrice.Text = Convert.ToDecimal(item.Row["SalePrice"]).ToString("f2");
            this._SalePriceLowest.Text = Convert.ToDecimal(item.Row["SalePriceLowest"]).ToString("f2");
        }

        private void lookUpEditItem_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
                lookUpEditItem_Leave(sender, e);
        }
    }
}
